#58. 最后一个单词的长度

def lengthOfLastWord(s):
    length=0
    for i in range(len(s)-1,-1,-1):
        if s[i]!=" ":
            length+=1
        elif length>0 and s[i]==" ":
            break
        elif length==0 and s[i]==" ":
            continue
    return length

print(lengthOfLastWord("Hello World"))
print(lengthOfLastWord("   fly me   to   the moon  "))
print(lengthOfLastWord("luffy is still joyboy"))
